package com.bill99.golden.inf.sso.controller;

import org.apache.log4j.Logger;

import com.bill99.golden.inf.sso.service.TokenDBService;
import com.opensymphony.xwork2.ActionContext;
import com.ryan.framework.action.BaseAction;

public class LoadTokenFromDBController extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	private String indexView;
	private TokenDBService tokenDBService;
	private Logger logger=Logger.getLogger(this.getClass());
	public String index() throws Exception {
		ActionContext actionContext =this.getActionContext();
		actionContext.put("randomCode", (long) (Math.random() * 1000000));
		logger.info("LoadTokenFromDBController:::");
		return SUCCESS;
	}

	public String loadTokenFromDB() throws Exception {
		Object code = this.getParameters().get("code");
		Object myCode = this.getParameters().get("myCode");
		if(null==code){
			return this.index();
		}else if(code.equals(myCode)){
			return this.index();
		}
		this.tokenDBService.loadTokenFromDB();
		this.getActionContext().put("msg", "从数据库装载令牌数据成功！");
		return SUCCESS;
	}

	public String getIndexView() {
		return indexView;
	}

	public void setIndexView(String indexView) {
		this.indexView = indexView;
	}

	public TokenDBService getTokenDBService() {
		return tokenDBService;
	}

	public void setTokenDBService(TokenDBService tokenDBService) {
		this.tokenDBService = tokenDBService;
	}

}
